//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.diary;

import java.awt.*;
import javax.swing.*;
import org.jpgolay.wi.customer.CustomerPanelGUI;
import org.jpgolay.wi.realestate.RealEstatePanelGUI;

public class DiaryDetailsPanelGUI extends JPanel {

    public DiaryDetailsPanelGUI() {
        mainPanel = null;
        yearPanel = null;
        lastButton = null;
        yearButton = null;
        nextButton = null;
        realEstatePanelGUI = null;
        customerPanelGUI = null;
        initialize();
    }

    private void initialize() {
        setLayout(new BorderLayout());
        setSize(500, 150);
        add(getMainPanel(), "Center");
        add(getYearPanel(), "South");
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            GridLayout gridLayout1 = new GridLayout();
            mainPanel = new JPanel();
            mainPanel.setLayout(gridLayout1);
            gridLayout1.setRows(1);
            gridLayout1.setColumns(2);
            mainPanel.add(getRealEstatePanelGUI(), null);
            mainPanel.add(getCustomerPanelGUI(), null);
        }
        return mainPanel;
    }

    private JPanel getYearPanel() {
        if (yearPanel == null) {
            yearPanel = new JPanel();
            yearPanel.add(getLastButton(), null);
            yearPanel.add(getYearButton(), null);
            yearPanel.add(getNextButton(), null);
        }
        return yearPanel;
    }

    private JButton getLastButton() {
        if (lastButton == null) {
            lastButton = new JButton();
            lastButton.setToolTipText("Ann\351e pr\351c\351dente");
            lastButton.setPreferredSize(new Dimension(20, 20));
            lastButton.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/arrowLeft18x18.png")));
            lastButton.setBorderPainted(false);
            lastButton.setContentAreaFilled(false);
            lastButton.setFocusPainted(false);
        }
        return lastButton;
    }

    private JButton getYearButton() {
        if (yearButton == null) {
            yearButton = new JButton();
            yearButton.setToolTipText("Ann\351e en cours");
            yearButton.setPreferredSize(new Dimension(100, 20));
            yearButton.setBorderPainted(false);
            yearButton.setContentAreaFilled(false);
            yearButton.setFocusPainted(false);
        }
        return yearButton;
    }

    private JButton getNextButton() {
        if (nextButton == null) {
            nextButton = new JButton();
            nextButton.setToolTipText("Ann\351e suivante");
            nextButton.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/arrowRight18x18.png")));
            nextButton.setPreferredSize(new Dimension(20, 20));
            nextButton.setBorderPainted(false);
            nextButton.setContentAreaFilled(false);
            nextButton.setFocusPainted(false);
        }
        return nextButton;
    }

    private RealEstatePanelGUI getRealEstatePanelGUI() {
        if (realEstatePanelGUI == null) {
            realEstatePanelGUI = new RealEstatePanelGUI();
        }
        return realEstatePanelGUI;
    }

    private CustomerPanelGUI getCustomerPanelGUI() {
        if (customerPanelGUI == null) {
            customerPanelGUI = new CustomerPanelGUI();
        }
        return customerPanelGUI;
    }

    public JButton getLast() {
        return getLastButton();
    }

    public JButton getYear() {
        return getYearButton();
    }

    public JButton getNext() {
        return getNextButton();
    }

    public RealEstatePanelGUI getRealEstatePanel() {
        return getRealEstatePanelGUI();
    }

    public CustomerPanelGUI getCustomerPanel() {
        return getCustomerPanelGUI();
    }
    private JPanel mainPanel;
    private JPanel yearPanel;
    private JButton lastButton;
    private JButton yearButton;
    private JButton nextButton;
    private RealEstatePanelGUI realEstatePanelGUI;
    private CustomerPanelGUI customerPanelGUI;
}
